package com.sgb.trip.view.adapter;

import android.content.Context;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.bumptech.glide.Glide;
import com.sgb.trip.R;
import com.sgb.trip.databinding.TripItemFlightInfoBinding;
import com.sgb.trip.entity.FlightInfoEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.NumberUtil;

import java.util.List;

/**
 * Time:2021/6/18
 * Author:黄淋
 * Description:
 */
public class FlightInfoAdapter extends BaseRecycleAdapter<FlightInfoEntity> {

    public FlightInfoAdapter(Context context, List<FlightInfoEntity> datas) {
        super(context, R.layout.trip_item_flight_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, FlightInfoEntity entity) {
        TripItemFlightInfoBinding binding = DataBindingUtil.bind(holder.itemView);

        if (!entity.getFromDate().equals(entity.getToDate())) {
            binding.tvDatePlus.setVisibility(View.VISIBLE);
        } else {
            binding.tvDatePlus.setVisibility(View.GONE);
        }
        binding.tvStartTime.setText(entity.getFromDateTime());
        binding.tvArriveTime.setText(entity.getToDateTime());

        binding.tvStartAirport.setText(String.format("%s%s", entity.getFromAirportName(), entity.getFromTerminal()));
        binding.tvArriveAirport.setText(String.format("%s%s", entity.getToAirportName(), entity.getToTerminal()));
        Glide.with(context).load(entity.getLogo()).into(binding.ivFlightCompany);
        binding.tvPrice.setText(NumberUtil.format(entity.getMinimumPrice(), 0));

        binding.tvFlightInfo.setText(String.format("%s%s  |  %s  |  %s", entity.getAirlineCompany(), entity.getFlightNo(), entity.getCraftType(), String.format("%sh%sm", NumberUtil.trim0(entity.getFlyDuration().split(":")[0]),
                NumberUtil.trim0(entity.getFlyDuration().split(":")[1]))));

        binding.tvPriceDiscount.setText(String.format("%s%s", "经济舱", entity.getMinimumDiscount() >= 1.0 ? "" :
                (NumberUtil.format(entity.getMinimumDiscount() * 10, 1) + "折起")));
    }
}
